package Lee_code;

import java.util.Arrays;

/**
 * @author blh
 * @date 2024年08月26日 15:15
 */
public class Lee_238_826 {
    public int[] productExceptSelf(int[] nums) {
        int len = nums.length;
        int[] left = new int[len];
        int[] right = nums;
        Arrays.fill(left, 1);

        int[] res = new int[len];
        for (int i = 0; i < len; i++) {
            right[i] = 1;
            res[i] = Arrays.stream(left).reduce(1, (a, b) -> a * b)
                    * Arrays.stream(right).reduce(1, (a, b) -> a * b);
            left[i] = nums[i];
        }
        return res;
    }
}
